package com.zhixin.fans.ks.ui.history;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.ui.base.BaseNeedLoginFragmentActivity;
import com.zhixin.fans.ks.ui.main.MainPageFragmentAdapter;

import org.eenie.common.base.BaseFragment;
import org.eenie.common.views.TopBarLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class OrderRecordActivity extends BaseNeedLoginFragmentActivity implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {
    public static final String ROUTE_PATH = "/charge/charge_history";


    @BindView(R.id.top_bar)
    TopBarLayout mTopBar;
    @BindView(R.id.page_fragment)
    ViewPager mPageFragment;

    List<BaseFragment> mFragments = new ArrayList<>();

    MainPageFragmentAdapter mMainPageFragmentAdapter;
    @BindView(R.id.ra_order_history)
    RadioButton mRaOrderHistory;
    @BindView(R.id.ra_charge_history)
    RadioButton mRaChargeHistory;
    @BindView(R.id.rg_taber)
    RadioGroup mRgTaber;

    @Override
    public int initContentView() {
        return R.layout.activity_order_record;
    }

    @Override
    public void initInjector() {

    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mFragments.add(new OrderHistoryFragment("订单记录"));
        mFragments.add(new ChargeHistoryFragment("粉币记录"));


        mPageFragment.setOffscreenPageLimit(mFragments.size());
        mPageFragment.setAdapter(mMainPageFragmentAdapter = new MainPageFragmentAdapter(getSupportFragmentManager(), mFragments));


        mPageFragment.addOnPageChangeListener(this);
        mRgTaber.setOnCheckedChangeListener(this);

    }


    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int viewId) {
        switch (viewId) {
            case R.id.ra_order_history:
                mPageFragment.setCurrentItem(0);
                break;
            case R.id.ra_charge_history:
                mPageFragment.setCurrentItem(1, true);
                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mRgTaber.check(mRgTaber.getChildAt(position).getId());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
